<?php
# 导入数据库接口文件
require_once 'dr-app-config.php';
require_once 'dr-app-functions.php';
require_once 'dr-db-reputations.php';

# 获得用户的请求
$action = isset($_POST['action']) ? $_POST['action'] : '';
//$action = 'mark_question';
switch ($action) {
	case 'get_reputation_settings':
		echo dr_get_reputation_settings();
		break;
	case 'update_all_reputation_settings':
		echo dr_update_all_reputation_settings();
		break;
	default:
		echo '';
}

/**
 * XXX 从数据库中获取积分系统的配置信息
 *
 * @return json 积分配置
 */
function dr_get_reputation_settings()
{
	$rep_settings = dr_db_get_reputation_settings();
	return json_encode($rep_settings);
}

/**
 * XXX 设置动作对应的积分数值
 *
 * @return
 */
function dr_update_all_reputation_settings()
{
	$reputation_settings = json_decode($_POST['reputation_settings'], true);
	$result = dr_db_update_all_reputation_settings($reputation_settings);
	if ($result) {
		return '{"ret":1}';
	}
	return '{"ret":0}';
}